package com.xky.rabbitmq.component;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author keying.xia
 * @date 2017/12/8
 */
@Component
public class AmqpComponent {

    @Autowired
    private AmqpTemplate amqpTemplate;


    public void send(String str){
        for (int i = 0 ; i < 100 ; i ++){
            this.amqpTemplate.convertAndSend("hello.queue" ,str+i);
        }
    }

    @RabbitListener(queues = "hello.queue")
    @RabbitHandler
    public void receiveMessage(String text){
        System.out.println("receive :" + text);
    }

    @RabbitListener(queues = "hello.queue")
    @RabbitHandler
    public void receiveMessage1(String text){
        System.out.println("receive2 :" + text);
    }



}
